
package com.android.formula.task;

import java.util.ArrayList;

import android.content.Context;

import com.android.formula.common.MyApplication;
import com.android.formula.dao.LanguageDao;
import com.android.formula.database.SQLiteTable;
import com.android.formula.model.Language;

/**
 * Get a Spot by Id
 */
public class GetLanguageDBTask extends BaseDatabaseTask<Language, ArrayList<Language>> {

    public GetLanguageDBTask(Context context,
            IDataEventHandler<ArrayList<Language>> dataEventHandler) {
        super(context, null, null, dataEventHandler);
    }

    @Override
    protected ArrayList<Language> execute() {
        SQLiteTable sqlt = MyApplication.getSqLiteTable();
        if (sqlt == null) {
            return null;
        }

        sqlt.open();
        LanguageDao dao = new LanguageDao(Language.class, mContext, sqlt.getDatabase());
        ArrayList<Language> list = dao.getAll();
        sqlt.close();
        if (!list.isEmpty()) {
            return list;
        } else {
            return null;
        }
    }
}
